from django.db import models
from utils.BaseModel import BaseModel
# Create your models here.
class UserModel(BaseModel):
    username = models.CharField(max_length=32,unique=True,verbose_name="账号")
    password = models.CharField(max_length=32)
    phone = models.CharField(max_length=11,unique=True,verbose_name="手机号")
    email = models.EmailField(unique=True)
    headimg=models.CharField(max_length=100,null=True,blank=True,verbose_name="头像")
    intro= models.CharField(max_length=255,verbose_name="简介",default="")
    score=models.IntegerField(verbose_name="积分",default=100)
    level=models.IntegerField(choices=((0,"普通会员"),(1,"银牌"),(2,"金牌")),default=0)
    class Meta:
        db_table = 'fguser'
    def __str__(self):
        return self.username


class CouponModel(BaseModel):
    name = models.CharField(max_length=32,verbose_name="优惠券名称")
    price = models.IntegerField(verbose_name="优惠券金额")
    end_time = models.DateTimeField(verbose_name="结束时间")
    number= models.IntegerField(verbose_name="数量")
    condition=models.CharField(verbose_name="使用条件",max_length=255)
    desc=models.CharField(verbose_name="简介",max_length=255)
    class Meta:
        db_table = 'fgcoupon'
    def __str__(self):
        return self.name
class  UserCoupon(BaseModel):
    user=models.ForeignKey(UserModel,on_delete=models.CASCADE,verbose_name="用户")
    coupon=models.ForeignKey(CouponModel,on_delete=models.CASCADE,verbose_name="优惠券")
    isused=models.BooleanField(verbose_name="是否使用",default=False)
    class Meta:
        db_table = 'fgusercoupon'
